import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 变形术
 **/
export default class FS_Polymorphy extends AbilityBase {
    static instance: FS_Polymorphy;
    buffType: AppBuffType = {
        id: 'buff_FS_Polymorphy',
        art: this.art,
        name: this.abilityName,
        ubertip: '该单位正在被变形',
        dur: 5,
        interval: 0.5,
        onInterval: this.buffInterval.bind(this),
    };
    constructor(id: string) {
        super(id);
        FS_Polymorphy.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        // let buff = BuffUtil.addBuff(target, this.buffType.id, source);
        let lv = this.getAbilityLevel(source);
        // buff.durMS = lv * 500 + 1500;
        BuffCommon.addBuff({
            target,
            caster: source,
            buffTypeId: this.buffType.id,
            ablityId: this.id,
            config: {
                dur: lv * 0.5 + 1.5,
            },
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    buffInterval(buff: Buff) {
        let lv = this.getAbilityLevel(buff.getCaster());
        let dmg = 50 * lv + UnitCommon.取法强(buff.getCaster()) * 0.5 * lv;
        DamageSystemInstance.applyArcaneDamage(buff.getParent(), buff.getCaster(), dmg, this.id, true);
    }
}
